/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.business.domain.Jsxx;
import me.zhengjie.business.domain.Jzdj;
import me.zhengjie.business.domain.vo.*;
import me.zhengjie.business.repository.JsxxRepository;
import me.zhengjie.business.service.ZhsqService;
import me.zhengjie.business.service.dto.ZhsqDto;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
import me.zhengjie.business.repository.JzdjRepository;
import me.zhengjie.business.service.JzdjService;
import me.zhengjie.business.service.dto.JzdjDto;
import me.zhengjie.business.service.dto.JzdjQueryCriteria;
import me.zhengjie.business.service.mapstruct.JzdjMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.math.BigDecimal;
import java.util.*;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.StoredProcedureQuery;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @description 服务实现
* @author xiahongbo
* @date 2022-06-06
**/
@Slf4j
@Service
@RequiredArgsConstructor
public class JzdjServiceImpl implements JzdjService {

    private final JzdjRepository jzdjRepository;
    private final JzdjMapper jzdjMapper;
    private final ZhsqService zhsqService;
    private final JsxxRepository jsxxRepository;

    @PersistenceContext
    private EntityManager em;

    @Override
    public Map<String, Object> queryAll(JzdjQueryCriteria criteria, Pageable pageable) {
        Page<Jzdj> page = jzdjRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        return PageUtil.toPage(page.map(jzdjMapper::toDto));
    }

    @Override
    public List<JzdjDto> queryAll(JzdjQueryCriteria criteria) {
        return jzdjMapper.toDto(jzdjRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
    }

    /**
     * 查询在院人员，即已经就诊登记的人员
     *
     * @param pageable 条件参数
     * @return List<JzdjDto>
     */
    @Override
    public Map<String, Object> queryZyry(String yljgdm, String sfz, Pageable pageable) {

        Page<ZyryVo> page = jzdjRepository.queryList(yljgdm, sfz, pageable);
        return PageUtil.toPage(page);
    }

    @Override
    public JzdjDto findJzjl(String sfz) {
        Jzdj jzdj = jzdjRepository.findJzjl(sfz);
        log.info("findJzjl {} ", jzdj);
        return jzdjMapper.toDto(jzdj);
    }

    @Override
    public FyxxVo queryLocalFyxx(Long jzid) {
        List<Object> list = jzdjRepository.queryLocalFyxx(jzid);
        FyxxVo vo = new FyxxVo();
        for (Object obj : list) {
            Object[] arr = (Object[]) obj;

            vo.setZl(arr[0]);
            vo.setRyrq(arr[1]);
            vo.setCyrq(arr[2]);
            vo.setZfy(arr[3]);
            vo.setWsc(arr[4]);
            vo.setYsc(arr[5]);
        }
        log.info("fyxxVo {} ", vo);
        return vo;
    }

    @Override
    @Transactional
    public JzdjDto findById(Long bisJzdjId) {
        Jzdj jzdj = jzdjRepository.findById(bisJzdjId).orElseGet(Jzdj::new);
        ValidationUtil.isNull(jzdj.getBisJzdjId(), "Jzdj", "bisJzdjId", bisJzdjId);
        return jzdjMapper.toDto(jzdj);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public JzdjDto create(Jzdj resources) {
        String ryrq = resources.getBisJzdjRyrq().replaceAll("-", "").substring(0, 8);
        String sfz = resources.getBisJzdjSfz();
        Jzdj isExist = jzdjRepository.isZy(sfz, ryrq);
        if(isExist != null) {
            String temp_ryrq = isExist.getBisJzdjRyrq();
            String temp_cyrq = isExist.getBisJzdjCyrq();
            throw new BadRequestException("此长者入院日期" + ryrq + "，与" + temp_ryrq + "~" + temp_cyrq + "的结算周期冲突");
        }
        String date = DateUtil.format(new Date(), "yyyyMMdd");
        String jbrxm = SecurityUtils.getCurrentNickName();

        int ramdom1 = (int) ((Math.random() * 9 + 1) * 10000000);
        int ramdom2 = (int) ((Math.random() * 9 + 1) * 10000000);
        String jzlsh = date + ramdom1;
        String fph = date + ramdom2;

        // 交易类型（1登记，2修改，3出院登记，-1无费退院/退号）
        resources.setBisJzdjJylx("1");
        // 就诊流水号
        resources.setBisJzdjLsh(jzlsh);
        // 医疗类别
        resources.setBisJzdjYllb(DefaultUtil.YLLB_JG);
        // 入院日期
        resources.setBisJzdjRyrq(ryrq);
        // 出院日期（空）
        // 入院疾病编码
        resources.setBisJzdjRyjbbm(DefaultUtil.JBBM_JG);
        // 挂号费
        resources.setBisJzdjGhf(0l);
        // 诊查费
        resources.setBisJzdjZcf(0l);
        // 出院疾病编码
        resources.setBisJzdjCyjbbm(DefaultUtil.JBBM_JG);
        // 经办人
        resources.setBisJzdjJbr(jbrxm);
        // 经办日期
        resources.setBisJzdjJbrq(date);
        // 发票号
        resources.setBisJzdjFph(fph);
        // 出院状态
        resources.setBisJzdjCyzt("0");
        // 审批人
        resources.setBisJzdjSpr(jbrxm);
        // 转出医院名称（空）
        log.info("create {} ", resources);
        JzdjDto jzdjDto = jzdjMapper.toDto(jzdjRepository.save(resources));
        return jzdjDto;
    }

    @Override
    public void makeJzdj84(Long jzid, String cyrq, String jylx) {
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 开始");
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - jzid:{}", jzid);
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - cyrq:{}", cyrq);
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 交易类型 1登记，2修改，3出院登记，-1无费退院/退号");
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - jylx:{}", jylx);
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 执行 PRC_MAKE_JZDJ_STR84");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeJzdj84");

        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(SecurityUtils.getCurrentUserId()));
        storedProcedureQuery.setParameter("IR_JZID", String.valueOf(jzid));
        storedProcedureQuery.setParameter("IR_YWBM", jylx);
        storedProcedureQuery.setParameter("IR_CYRQ", cyrq.replaceAll("-", ""));

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 结束 :code:{}，msg:{}", code, msg);
        if (code == 1) {
            log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 已入院");
            if("-1".equals(jylx)) {
                log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 无费退院/退号，更新登记表交易类型[jylx]");
                Jzdj jzdj = new Jzdj();
                jzdj.setBisJzdjId(jzid);
                jzdj.setBisJzdjJylx(jylx);
                this.update(jzdj);
            }
        } else {
            if ("1".equals(jylx)) {
                Long[] ids = {jzid};
                this.deleteAll(ids);
            }
            throw new BadRequestException(msg);
        }
    }

    @Override
    public String makeFymx84(Long jzid) {
        log.info("[JzdjServiceImpl - makeFymx84]--------------- 机构执行费用明细上报 - 开始");
        log.info("[JzdjServiceImpl - makeFymx84]--------------- 机构执行费用明细上报 - jzid:{}", jzid);
        log.info("[JzdjServiceImpl - makeFymx84]--------------- 机构执行费用明细上报 - 执行 PRC_MAKE_FYMX_STR84");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeFymx84");

        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(SecurityUtils.getCurrentUserId()));
        storedProcedureQuery.setParameter("IR_JZID", String.valueOf(jzid));

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeFymx84]--------------- 机构执行费用明细上报 - 结束 :code:{}，msg:{}", code, msg);
        String rsMsg = "";
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
        return rsMsg;
    }

    @Override
    public String deleteFymx(Long jzid) {
        log.info("[JzdjServiceImpl - deleteFymx]--------------- 机构执行删除所有费用明细 - 开始");
        log.info("[JzdjServiceImpl - deleteFymx]--------------- 机构执行删除所有费用明细 - jzid:{}", jzid);
        log.info("[JzdjServiceImpl - deleteFymx]--------------- 机构执行删除所有费用明细 - 执行 PRC_DELETE_FYMX_STR");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("deleteFymx");

        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(SecurityUtils.getCurrentUserId()));
        storedProcedureQuery.setParameter("IR_JZID", String.valueOf(jzid));

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - deleteFymx]--------------- 机构执行删除所有费用明细 - 结束 :code:{}，msg:{}", code, msg);
        String rsMsg = "";
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
        return rsMsg;
    }

    @Override
    public String makeFymx84Single(Long fyid, String ywbm) {
        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - 开始");
        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - fyid:{}", fyid);
        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - 交易类型 1收费，-1退费");
        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - ywbm:{}", ywbm);
        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - 执行 PRC_MAKE_FYMX_STR84_SINGLE");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeFymx84Single");

        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(SecurityUtils.getCurrentUserId()));
        storedProcedureQuery.setParameter("IR_FYID", String.valueOf(fyid));
        storedProcedureQuery.setParameter("IR_YWBM", ywbm);

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeFymx84Single]--------------- 机构执行单独费用上报 - 结束 :code:{}，msg:{}", code, msg);
        String rsMsg = "";
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
        return rsMsg;
    }

    @Override
    public String makeFyjs84(Long jzid, String jylx) {
        log.info("[JzdjServiceImpl - makeFyjs84]--------------- 机构执行结算 - 开始");
        log.info("[JzdjServiceImpl - makeFyjs84]--------------- 机构执行结算 - jzid:{}", jzid);
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - 交易类型 0结算，1预结，-2退费，-3清方退费（需重新上传处方）");
        log.info("[JzdjServiceImpl - makeJzdj84]--------------- 机构执行入院登记 - jylx:{}", jylx);
        log.info("[JzdjServiceImpl - makeFyjs84]--------------- 机构执行结算 - 执行 PRC_MAKE_FYMX_STR84");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeFyjs84");

        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(SecurityUtils.getCurrentUserId()));
        storedProcedureQuery.setParameter("IR_JZID", String.valueOf(jzid));
        storedProcedureQuery.setParameter("IR_YWBM", jylx);

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeFyjs84]--------------- 机构执行结算 - 结束 :code:{}，msg:{}", code, msg);
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
        return msg;
    }

    @Override
    public void saveFyjs84(String msg, String cyrq, Long jzid) {
        JzdjDto jzdjDto = this.findById(jzid);
        String ryrq = jzdjDto.getBisJzdjRyrq();
        ZhsqDto zhsqDto = zhsqService.findById(jzdjDto.getBisJzdjZhsqId());

        Date ryrqDate = DateTimeUtil.parse(ryrq, DateTimeUtil.DEFAULT_DATE_FORMAT);
        Date cyrqDate = DateTimeUtil.parse(cyrq, DateTimeUtil.DEFAULT_DATE_FORMAT);


        String[] jsArray = msg.split("\\|");

        Jsxx jsxx = new Jsxx();
        jsxx.setBisJsxxId(UUID.randomUUID().toString());
        jsxx.setBisJsxxZhid(zhsqDto.getBisZhsqId());
        jsxx.setBisJsxxJzid(jzid);
        jsxx.setBisJsxxXm(zhsqDto.getBisZhsqSnryXm());
        jsxx.setBisJsxxSfz(zhsqDto.getBisZhsqSnrySfz());
        jsxx.setBisJsxxLsh(jzdjDto.getBisJzdjLsh());
        // jsxx.setBisJsxxJssj(DateTimeUtil.getNow());
        jsxx.setBisJsxxYlzfy(new BigDecimal(jsArray[1]));
        jsxx.setBisJsxxTczf(new BigDecimal(jsArray[24]));
        jsxx.setBisJsxxGrxj(new BigDecimal(jsArray[25]));
        jsxx.setBisJsxxDjh(jsArray[36]);
        jsxx.setBisJsxxTcbl(jsArray[42]);
        jsxx.setBisJsxxYljgmc(zhsqDto.getHljg().getBisGsglQymc());
        jsxx.setBisJsxxYljgbm(zhsqDto.getHljg().getBisGsglYljgdm());
        jsxx.setBisJsxxYbkh(zhsqDto.getBisZhsqYbkh());
        jsxx.setBisJsxxSftf("0");
        jsxx.setBisJsxxRyrq(ryrqDate);
        jsxx.setBisJsxxCyrq(cyrqDate);
        // jsxx.setBisJsxxZyts(DateTimeUtil.diffDays(cyrqDate, ryrqDate) + 1);


        jsxxRepository.save(jsxx);

    }

    @Override
    public void saveQftf84(String jsxxId) {

        Jsxx jsxx = jsxxRepository.findById(jsxxId).orElseGet(Jsxx::new);

        jsxx.setBisJsxxSftf("1");
        jsxx.setBisJsxxTfsj(DateTimeUtil.getNow());

        jsxxRepository.save(jsxx);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Jzdj resources) {
        // String ryrq = resources.getBisJzdjRyrq().replaceAll("-", "").substring(0, 8);
        //    String jbrq = resources.getBisJzdjJbrq().replaceAll("-", "").substring(0, 8);
        Jzdj jzdj = jzdjRepository.findById(resources.getBisJzdjId()).orElseGet(Jzdj::new);
        ValidationUtil.isNull(jzdj.getBisJzdjId(), "Jzdj", "id", resources.getBisJzdjId());
        jzdj.copy(resources);

        // jzdj.setBisJzdjRyrq(ryrq);
        //    jzdj.setBisJzdjJbrq(jbrq);
        jzdjRepository.save(jzdj);
    }

    @Override
    public void deleteAll(Long[] ids) {
        for (Long bisJzdjId : ids) {
            jzdjRepository.deleteById(bisJzdjId);
        }
    }

    @Override
    public void download(List<JzdjDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (JzdjDto gs : all) {
            Map<String, Object> map = new LinkedHashMap<>();
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }

    @Override
    public List<PersonFeeVo> queryPersonFee(String ryxx, String djrq, String cblx) {
        String nd = djrq.substring(0, 4);
        djrq = djrq.replace("-", "").substring(0, 6);
        String start = nd + "01";
        String end = nd + "12";
        List<PersonFeeVo> list = new ArrayList<PersonFeeVo>();
        if("".equals("职工")) {
            list = jzdjRepository.queryPersonFee310(ryxx, djrq, start, end);
        } else {
            list = jzdjRepository.queryPersonFee390(ryxx, start, end);
        }
        return list;
    }

    @Override
    public Map<String,Object> queryJzdjResultVo(String kfrq, String jgbm, String ksmc, String sndj, String ryxx) {
        List<JzdjResultVo> list = new ArrayList<>();
        String kfrqSql = StringUtils.isEmpty(kfrq) ? "" : " AND R3.BIS_FYMX_KFRQ= :kfrq ";
        String ksmcSql = StringUtils.isEmpty(ksmc) ? "" : " AND R2.BIS_JZDJ_KSMC= :ksmc ";
        String sndjSql = StringUtils.isEmpty(sndj) ? "" : " AND R1.BIS_ZHSQ_SNDJ= :sndj ";
        String ryxxSql = StringUtils.isEmpty(ryxx) ? "" : " AND (R1.BIS_ZHSQ_SNRY_XM= :ryxx or R1.BIS_ZHSQ_SNRY_SFZ= :ryxx) ";
        String sql = "SELECT R1.BIS_ZHSQ_ID, " +
                "       R2.BIS_JZDJ_ID, " +
                "       R1.BIS_ZHSQ_SNRY_XM, " +
                "       R1.BIS_ZHSQ_SNRY_SFZ, " +
                "       SUM(R3.BIS_FYMX_ZJ) DRFY, " +
                "       COUNT(DISTINCT R3.BIS_FYMX_KFRQ) TS, " +
                "       SUM(DISTINCT R2.BIS_JZDJ_JS_TCZF) TCZF, " +
                "       SUM(DISTINCT R2.BIS_JZDJ_JS_XJZF) XJZF, " +
                "       R2.BIS_JZDJ_JS_BL BL, " +
                "       R2.BIS_JZDJ_JS_RS RESULT, " +
                "       R2.BIS_JZDJ_RYRQ, " +
                "       R1.BIS_ZHSQ_SNDJ, " +
                "       R1.BIS_ZHSQ_CBLX " +
                "  FROM BIS_ZHSQ R1 " +
                " INNER JOIN BIS_JZDJ R2 ON R1.BIS_ZHSQ_ID = R2.BIS_JZDJ_ZHSQ_ID " +
                "  LEFT JOIN BIS_FYMX R3 ON R2.BIS_JZDJ_ID = R3.BIS_FYMX_JZDJ_ID " + kfrqSql +
                " WHERE 1 = 1 " +
                "   AND R2.BIS_JZDJ_CYZT = '0' " +
                "   AND R1.BIS_ZHSQ_HLJG_BM = :jgbm " + ksmcSql + sndjSql + ryxxSql +
                " GROUP BY R1.BIS_ZHSQ_SNRY_XM, " +
                "          R1.BIS_ZHSQ_SNRY_SFZ, " +
                "          R2.BIS_JZDJ_ID, " +
                "          R1.BIS_ZHSQ_ID, " +
                "          R2.BIS_JZDJ_JS_BL, " +
                "          R2.BIS_JZDJ_JS_RS, " +
                "          R2.BIS_JZDJ_RYRQ, " +
                "          R1.BIS_ZHSQ_SNDJ, " +
                "          R1.BIS_ZHSQ_CBLX " +
                " ORDER BY R1.BIS_ZHSQ_ID ";
        Query adlXmQuery = em.createNativeQuery(sql);
        adlXmQuery.setParameter("jgbm", jgbm);
        if(StringUtils.isNotEmpty(kfrq)) {
            adlXmQuery.setParameter("kfrq", kfrq);
        }
        if(StringUtils.isNotEmpty(ksmc)) {
            adlXmQuery.setParameter("ksmc", ksmc);
        }
        if(StringUtils.isNotEmpty(sndj)) {
            adlXmQuery.setParameter("sndj", sndj);
        }
        if(StringUtils.isNotEmpty(ryxx)) {
            adlXmQuery.setParameter("ryxx", ryxx);
        }
        List adlXmList = adlXmQuery.getResultList();
        for(Object adlXmObj : adlXmList) {
            JzdjResultVo jzdjResultVo = new JzdjResultVo();
            Object[] adlXmArr = (Object[]) adlXmObj;
            Object zhid = adlXmArr[0] == null ? "" : adlXmArr[0];
            Object jzid = adlXmArr[1] == null ? "" : adlXmArr[1];
            Object xm = adlXmArr[2] == null ? "" : adlXmArr[2];
            Object sfz = adlXmArr[3] == null ? "" : adlXmArr[3];
            Object ljfy = adlXmArr[4] == null ? "" : adlXmArr[4];
            Object ts = adlXmArr[5] == null ? "" : adlXmArr[5];
            Object tczf = adlXmArr[6] == null ? "" : adlXmArr[6];
            Object xjzf = adlXmArr[7] == null ? "" : adlXmArr[7];
            Object bl = adlXmArr[8] == null ? "" : adlXmArr[8];
            Object result = adlXmArr[9] == null ? "" : adlXmArr[9];
            Object ryrq = adlXmArr[10] == null ? "" : adlXmArr[10];
            Object sndj1 = adlXmArr[11] == null ? "" : adlXmArr[11];
            Object cblx1 = adlXmArr[12] == null ? "" : adlXmArr[12];
            jzdjResultVo.setBisZhsqId(zhid);
            jzdjResultVo.setBisJzdjId(jzid);
            jzdjResultVo.setXm(xm);
            jzdjResultVo.setSfz(sfz);
            jzdjResultVo.setLjfy(ljfy);
            jzdjResultVo.setTs(ts);
            jzdjResultVo.setTczf(tczf);
            jzdjResultVo.setXjzf(xjzf);
            jzdjResultVo.setBl(bl);
            jzdjResultVo.setJsResult(result);
            jzdjResultVo.setRyrq(ryrq);
            jzdjResultVo.setSndj(sndj1);
            jzdjResultVo.setCblx(cblx1);
            jzdjResultVo.setKfrq(kfrq);
            list.add(jzdjResultVo);
        }
        return PageUtil.toPage(list, list.size());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void makeFymxPl(String ids, String ryxx, String sndj, String kfrq, String jgbm, String masterId, Long userId) {
        log.info("[JzdjServiceImpl - makeFymxPl]--------------- 机构执行批量过方 - 开始");
        log.info("[JzdjServiceImpl - makeFymxPl]--------------- 机构执行批量过方 - 执行 PRC_MAKE_FYMX_PL");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeFymxPl");

        storedProcedureQuery.setParameter("IR_RYXX", ryxx);
        storedProcedureQuery.setParameter("IR_SNDJ", sndj);
        storedProcedureQuery.setParameter("IR_KFRQ", kfrq);
        storedProcedureQuery.setParameter("IR_JGBM", jgbm);
        storedProcedureQuery.setParameter("IR_MASTER_ID", masterId);
        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(userId));
        storedProcedureQuery.setParameter("IR_IDS", ids);

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeFymxPl]--------------- 机构执行批量过方 - 结束 :code:{}，msg:{}", code, msg);
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void makeYjsPl(String ids, String ryxx, String sndj, String jgbm, Long userId) {
        log.info("[JzdjServiceImpl - makeYjsPl]--------------- 机构执行批量预结算 - 开始");
        log.info("[JzdjServiceImpl - makeYjsPl]--------------- 机构执行批量预结算 - 执行 PRC_MAKE_YJS_PL");

        StoredProcedureQuery storedProcedureQuery = this.em.createNamedStoredProcedureQuery("makeYjsPl");

        storedProcedureQuery.setParameter("IR_RYXX", ryxx);
        storedProcedureQuery.setParameter("IR_SNDJ", sndj);
        storedProcedureQuery.setParameter("IR_JGBM", jgbm);
        storedProcedureQuery.setParameter("IR_USER_ID", String.valueOf(userId));
        storedProcedureQuery.setParameter("IR_IDS", ids);

        storedProcedureQuery.execute();
        int code = (int) storedProcedureQuery.getOutputParameterValue("OR_APPCODE");
        String msg = (String) storedProcedureQuery.getOutputParameterValue("OR_MESSAGE");

        log.info("[JzdjServiceImpl - makeYjsPl]--------------- 机构执行批量预结算 - 结束 :code:{}，msg:{}", code, msg);
        if (code == 1) {

        } else {
            throw new BadRequestException(msg);
        }
    }

}